import { IClean } from "../../../../com/gengine/core/IClean";
import { BuffItem } from "./BuffItem";
import { ObjectUtils } from "../../../../com/gengine/utils/ObjectUtils";
import { SkillStateConfig } from "../../resource/SkillStateConfig";
import { TState } from "../../../../Message/Db/Tables/TState";
import { BuffInfo } from "./BuffInfo";
type int = number;
//class BuffPanel
    
    export  class BuffPanel /* flash.display.Sprite */ implements IClean
    {
        constructor(arg1: int=5)
        {
            
            this._buffItemArray = [];
            this._buffDcit = new Map<any, any> /* flash.utils.Dictionary */();
            this._buffGroupDcit = new Map<any, any> /* flash.utils.Dictionary */();
            this._amount = arg1;
            this.init();
            return;
        }

        public get isHideAfterFine(): Boolean
        {
            return this._isHideAfterFine;
        }

        /* internal  */init(): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < this._amount) 
            {
                loc1 = new BuffItem();
                loc1.x = loc2 * 20;
                loc1.x = loc2 % 5 * 20;
                loc1.y = Math.floor(loc2 / 5) * 20;
                loc1.setSize(17, 17);
                loc1.scrollRect = new Object /* flash.geom.Rectangle */(0, 0, 17, 17);
                this.addChild(loc1);
                this._buffItemArray.push(loc1);
                ++loc2;
            }
            return;
        }

        public hideBuffAfterFine(): void
        {
            var loc1=0;
            if (this._amount > 5) 
            {
                if (this._buffItemArray.length > 5) 
                {
                    loc1 = 5;
                    while (loc1 < this._buffItemArray.length) 
                    {
                        (this._buffItemArray[loc1] as BuffItem).visible = false;
                        ++loc1;
                    }
                    this._isHideAfterFine = true;
                }
                else 
                {
                    this._isHideAfterFine = false;
                }
            }
            else 
            {
                this._isHideAfterFine = false;
            }
            return;
        }

        public showBuffAfterFine(): void
        {
            var loc1=0;
            if (this._amount > 5 && this._buffItemArray.length > 5) 
            {
                loc1 = 5;
                while (loc1 < this._buffItemArray.length) 
                {
                    (this._buffItemArray[loc1] as BuffItem).visible = true;
                    ++loc1;
                }
            }
            this._isHideAfterFine = false;
            return;
        }

        public updateBufferByTSateIdArray(arg1: Array<any>): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc1=[];
            this.clearDict();
            if (arg1) 
            {
                if (arg1.length > 0) 
                {
                    loc4 = 0;
                    while (loc4 < arg1.length) 
                    {
                        if ((loc3 = ObjectUtils.baseClone(SkillStateConfig.instance.getInfoByName(arg1[loc4])) as TState) && !(loc3.icon == "")) 
                        {
                            if (loc3) 
                            {
                                loc2 = new BuffInfo();
                                loc3.category = 3;
                                loc2.tstate = loc3;
                            }
                            else 
                            {
                                loc2 = null;
                            }
                            if (this._buffDcit[loc3.stateId] == null && this._buffGroupDcit[loc3.group] == null) 
                            {
                                loc1.push(loc2);
                                if (loc3.group > 0) 
                                {
                                    this._buffGroupDcit[loc3.group] = loc2;
                                }
                                else 
                                {
                                    this._buffDcit[loc3.stateId] = loc2;
                                }
                            }
                        }
                        ++loc4;
                    }
                    this.updateBufferByBuffInfoArray(loc1);
                }
                else 
                {
                    this.clearBuff();
                }
            }
            return;
        }

        /* internal  */clearDict(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=this._buffDcit;
            for (loc1 in loc4) 
            {
                delete this._buffDcit[loc1];
            }
            loc3 = 0;
            loc4 = this._buffGroupDcit;
            for (loc2 in loc4) 
            {
                delete this._buffGroupDcit[loc2];
            }
            return;
        }

        public updateBufferByBuffInfoArray(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            if (arg1) 
            {
                if (arg1.length > 0) 
                {
                    loc3 = 0;
                    while (loc3 < this._buffItemArray.length) 
                    {
                        loc1 = arg1[loc3] as BuffInfo;
                        loc2 = this._buffItemArray[loc3];
                        loc2.buffInfo = loc1;
                        ++loc3;
                    }
                }
                else 
                {
                    this.clearBuff();
                }
            }
            return;
        }

        /* internal  */clearBuff(): void
        {
            var loc2=null;
            var loc1=0;
            while (loc1 < this._buffItemArray.length) 
            {
                loc2 = this._buffItemArray[loc1] as BuffItem;
                if (loc2) 
                {
                    loc2.buffInfo = null;
                }
                ++loc1;
            }
            return;
        }

        public clean(): void
        {
            this.clearBuff();
            return;
        }

        /* internal */ /* var */_amount: int;

        /* internal */ /* var */_buffItemArray: Array<any>;

        /* internal */ /* var */_buffDcit: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_buffGroupDcit: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_isHideAfterFine: Boolean;
    }
